package com.lzq.model.prototype;

import java.io.*;

/**
 * @author : modify
 * @version : v1.0
 * @description :
 * @createTime : 2022/11/15 19:22
 * @updateUser : modify
 * @updateTime : 2022/11/15 19:22
 * @updateRemark :
 */
public class StudentPrototype implements Cloneable, Serializable {
    private Student stu;

    public Student getStu() {
        return stu;
    }

    public void setStu(Student stu) {
        this.stu = stu;
    }

    public void show() {
        System.out.println(stu.getName() + " <<<< ===== >>>> " + stu.getAddress());
    }

    @Override
    public StudentPrototype clone() {
        try {
            StudentPrototype clone = (StudentPrototype) super.clone();
            return clone;
        } catch (CloneNotSupportedException e) {
            throw new AssertionError();
        }
    }
}

class StudentPrototypeTest {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        StudentPrototype studentPrototype = new StudentPrototype();
        Student student = new Student("张三", "长沙");
        studentPrototype.setStu(student);
        //创建对象输出流对象
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("D:\\data\\b.txt"));
        //将c1对象写出到文件中
        oos.writeObject(studentPrototype);
        oos.close();

        //创建对象出入流对象
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("D:\\data\\b.txt"));

        StudentPrototype clone = (StudentPrototype) ois.readObject();
        clone.getStu().setName("李四");

        studentPrototype.show();
        clone.show();
    }
}